<?php
	// set up database info
	$usr = "appkudos";
	$pwd = "ak1234";
	$db = "appkudos";
	$host = "yangjustine.startlogicmysql.com";

	// establish connection
	$connection = mysql_connect($host,$usr,$pwd);
	if (!$connection) { echo("ERROR: " . mysql_error() . "\n"); }
	
	// get one user
	
	$username = $_REQUEST['username'];
	$firstname = $_REQUEST['firstname']; 
	$lastname = $_REQUEST['lastname']; 
	
	/*
	$username = "flytalk";
	$firstname = "fly"; 
	$lastname = "talk";*/
	
	//$sql = 'SELECT * FROM `User` WHERE `username` = \''.$username.'\'';
	//$username = "testuser6";
	//$firstname = "test";
	//$lastname = "user6";
	$sql = 'INSERT INTO `User` (`username`, `firstname`, `lastname`, `dateCreated`) VALUES (\''.$username.'\', \''.$firstname.'\', \''.$lastname.'\', CURRENT_TIMESTAMP);';
	
	// insert user into db
	mysql_db_query($db,"$sql",$connection);

	// get multiple users to see if the insert is successful
	$sql = 'SELECT * FROM `User`';
    $users = mysql_db_query($db,"$sql",$connection);

	if (!$users) {
    		echo("ERROR: " . mysql_error() . "\n$SQL\n"); 	
	}
	else{		
		while($user = mysql_fetch_array($users))
		{
			$lastuser = $user;           
		} 
		//print_r($lastuser);
		//print(json_encode($lastuser));
		
		// $cb = isset($_GET['callback']) ? $_GET['callback'] : '';
       
   		//  echo $cb . '({"results":' . json_encode($user_list) . '})';
		 $callback = $_GET['callback'];

		if ($callback) {
   			 header('Content-Type: text/javascript');
    		echo $callback . '({"results":' . json_encode($lastuser) . '});';
		} else {
    		header('Content-Type: application/x-json');
    		echo json_encode($lastuser);
		}	
	}

	mysql_close($connection);

?>